package com.demo.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.demo.model.MsgModel;

@Repository
public interface MsgMapper {
	
	@Insert("INSERT INTO msg(phone, info, time, ip) VALUES(#{phone},#{info},#{time},#{ip})")
	void insert(MsgModel msg);
	
	//手机号60秒内发送次数
	@Select("SELECT COUNT(*) AS sms_count FROM msg WHERE phone = #{phone} AND time >= DATE_SUB(NOW(), INTERVAL 60 SECOND)")
	int getCount1(MsgModel msg);
    
	//IP3秒内发送次数
	@Select("SELECT COUNT(*) AS sms_count FROM msg WHERE ip = #{ip} AND time >= DATE_SUB(NOW(), INTERVAL 3 SECOND)")
	int getCount2(MsgModel msg);
			
	        
	//IP每天发送条数
	@Select("SELECT COUNT(*) AS sms_count FROM msg WHERE ip = #{ip} AND time >= CURDATE() AND time < CURDATE() + INTERVAL 1 DAY")
	int getCount3(MsgModel msg);
}
